/**
 * 
 */
package com.arx.interactive;

import java.awt.Color;
import java.awt.Point;

import com.arx.common.GlobalConsts;
import com.arx.graphics.flyweight.ANIM_HANDLE;
import com.arx.graphics.flyweight.ANIM_USE;
import com.arx.interactive.data.FixData;
import com.arx.interactive.data.ItemData;
import com.arx.interactive.data.NPCData;
import com.arx.interactive.data.SpellCastData;
import com.arx.interactive.data.TweakInfo;
import com.arx.item.InventoryData;
import com.arx.script.flyweight.ScriptObject;
import com.dalonedrau.opengl.Vector3;

/**
 * @author Donald
 */
public final class InteractiveObject {
	private FixData[]		_fixdata;
	private ItemData		_itemdata;
	private NPCData			_npcdata;
	private long			aflags;													// private
	// additionnal flags
	private Vector3			angle;														// private
	private ANIM_USE[]		animlayer	= new ANIM_USE[GlobalConsts.MAX_ANIM_LAYERS];
	// IO
	// angle
	// private TextureContainer * inv; //private Object Icon
	// private EERIE_3DOBJ * obj; //private IO Mesh data
	/** Object Animations. */
	private ANIM_HANDLE[]	anims		= new ANIM_HANDLE[GlobalConsts.MAX_ANIMS];
	private char[]			armormaterial;
	private float			basespeed;
	// private EERIE_3D_BBOX bbox3D;
	private Point			bbox1;														// private
	// 2D
	// bounding
	// box1
	private Point			bbox2;														// private
																						// 2D
	// bounding box2
	private long			changeanim;
	private long			collide_door_time;
	private short			collision;													// private

	// collision
	// type
	private long			cstep;
	private long			damagedata;
	private short			damager_damages;
	/**
	 * Gets the damager_damages 
	 * @return {@link short}
	 */
	public short getDamager_damages() {
		return damager_damages;
	}
	/**
	 * Sets the damager_damages
	 * @param damager_damages the damager_damages to set
	 */
	public void setDamager_damages(short damager_damages) {
		this.damager_damages = damager_damages;
	}
	private long			damager_type;
	private float			dmg_sum;
	private float			durability;
	// private void * usepath;
	// private void * symboldraw;
	private short			dynlight;
	private short			EditorFlags;												// private
																						// 1
	// NOTSAVED 2
	// selected
	private float			fall;

	private String			filename;
	private short			flarecount;
	private Vector3			forcedmove;
	private float			frameloss;

	/** GFLAGS. */
	private int				gameFlags;
	private float			head_rot;
	/** Ident num. */
	private long			ident;
	private long			ignit_light;

	private long			ignit_sound;
	private float			ignition;
	/** Improve Vision Color (Heat). */
	private Color			infracolor;
	/** Initial Angle. */
	private Vector3			initangle;
	/** Initial Position. */
	private Vector3			initpos;
	// private IO_CAMDATA * _camdata; //private Camera Datas
	/** Inventory Data. */
	private InventoryData	inventory;
	private char[]			inventory_skin;
	private float			invisibility;
	private short			inzone_show;
	/** IO type. */
	private long			ioflags;
	private byte[][]		iogroups;
	private long			lastanimtime;
	private Vector3			lastmove;
	/** IO last position. */
	private Vector3			lastpos;
	private short			lastspeechflag;
	// private void * inzone;
	// private IO_HALO halo;
	// private IO_HALO halo_native;
	private short			level;

	/** localisation. */
	private char[]			locname		= new char[64];
	private String			mainevent;
	// private IO_TWEAKER_INFO * tweakerinfo; //private optional tweaker infos
	private long			material;
	private float			maxDurability;
	private Vector3			move;
	private short			nb_iogroups;
	// private EERIE_3D * lastanimvertex; //private Last Animation Positions of
	// Vertex
	private long			nb_lastanimvertex;
	private short			nb_spells_on;
	private short			no_collide;
	private float			original_height;

	private float			original_radius;
	private long			ouch_time;
	/** Overriding Script. */
	private ScriptObject	overScript;
	private char[]			padddd		= new char[3];
	private short			padding;
	private short			padding2;
	private short			poisonous;
	private short			poisonous_count;
	/** IO position. */
	private Vector3			pos;
	// private IO_PHYSICS physics; //private Movement Collision Data
	private short			room;
	/** 1==need_update. */
	private short			room_flags;
	private float			rubber;
	private float			scale;
	/** Primary Script. */
	private ScriptObject	script;

	/** Is This object Loaded by Script ? */
	private boolean			scriptload;
	private char			secretvalue;
	private short			sfx_flag;
	private long			sfx_time;
	private char[]			shop_category;
	private float			shopMultiplier;
	/** Show Status (In Scene, In Inventory...). */
	private short			show;
	private char			sizex;														// private
	// Inventory
	// Icon sizeX
	private char			sizey;														// private
	// Inventory
	// Icon sizeY
	// private char * usemesh; //private Alternate Mesh/private path
	// private EERIE_3DOBJ * tweaky; //private tweaked original obj backup
	private long			sound;
	private long			soundcount;
	private long			soundtime;
	private long			spark_n_blood;
	private float			speed_modif;
	private SpellCastData	spellcast_data;
	private int[]			spells_on;
	private short			stat_count;
	private short			stat_sent;
	private char[]			stepmaterial;

	private long			stopped;
	private char[]			strikespeech;
	private short			summoner;
	private Vector3			target;													// private
	// Target
	// position
	private int				targetinfo;												// private
	// Target
	// Type/private
	// Ident
	private short			truelevel;
	private short			Tweak_nb;
	private TweakInfo[]		Tweaks;
	private long			type_flags;												// private
	// object
	// type
	// (weapon,goblin...)
	private Vector3			velocity;													// private
	// velocity
	private char[]			weaponmaterial;
	private float			weight;
	public void addIOGroup(final byte[] group) {
		int len = iogroups.length;
		byte[][] temp = new byte[len + 1][];
		System.arraycopy(iogroups, 0, temp, 0, len);
		iogroups = temp;
		iogroups[len] = group;
		nb_iogroups++;
	}
	public void adjustInvisibility(final float val) {
		invisibility += val;
	}
	public void assignGameFlags(final int flag) {
		gameFlags |= flag;
	}
	public void assignIOFlags(final int flag) {
		ioflags |= flag;
	}
	public void clearIOGroups() {
		for (int i = 0; i < iogroups.length; i++) {
			iogroups[i] = null;
		}
	}
	public boolean equals(final InteractiveObject io) {
		return ident == io.ident;
	}
	/** Frees up memory associated with the spells_on array. */
	public void freeSpellsOnMemory() {
		spells_on = null;
		nb_spells_on = 0;
	}
	public ANIM_HANDLE getAnimation(final int index) {
		ANIM_HANDLE animation = null;
		if (index >= 0
				&& index < GlobalConsts.MAX_ANIMS) {
			animation = anims[index];
		}
		return animation;
	}
	public ANIM_USE getAnimationLayer(final int index) {
		ANIM_USE layer = null;
		if (index >= 0
				&& index < GlobalConsts.MAX_ANIM_LAYERS) {
			layer = animlayer[index];
		}
		return layer;
	}
	/**
	 * Gets the dmg_sum
	 * @return {@link float}
	 */
	public float getDmg_sum() {
		return dmg_sum;
	}
	public float getDurability() {
		return durability;
	}

	public String getFilename() {
		return filename;
	}
	public long getIdent() {
		return ident;
	}
	public long getIgnit_light() {
		return ignit_light;
	}
	/**
	 * Gets the ignition
	 * @return {@link float}
	 */
	public float getIgnition() {
		return ignition;
	}
	public InventoryData getInventory() {
		return inventory;
	}
	public float getInvisibility() {
		return invisibility;
	}
	public String getIOGroupAsString(final int index) {
		String group = null;
		if (iogroups != null
				&& index >= 0
				&& index < iogroups.length) {
			group = new String(iogroups[index]);
		}
		return group;
	}
	public ItemData getItemData() {
		return _itemdata;
	}
	/**
	 * Gets the lastanimtime
	 * @return {@link long}
	 */
	public long getLastanimtime() {
		return lastanimtime;
	}
	/**
	 * Gets the mainevent
	 * @return {@link String}
	 */
	public String getMainevent() {
		return mainevent;
	}
	public float getMaxDurability() {
		return maxDurability;
	}
	public short getNb_iogroups() {
		return nb_iogroups;
	}
	/**
	 * Gets the nb_lastanimvertex
	 * @return {@link long}
	 */
	public long getNb_lastanimvertex() {
		return nb_lastanimvertex;
	}
	/**
	 * Gets the nb_spells_on
	 * @return {@link short}
	 */
	public short getNb_spells_on() {
		return nb_spells_on;
	}
	/**
	 * Gets the _npcdata
	 * @return {@link NPCData}
	 */
	public NPCData getNpcdata() {
		return _npcdata;
	}
	/**
	 * Gets the ouch_time
	 * @return {@link long}
	 */
	public long getOuch_time() {
		return ouch_time;
	}
	/**
	 * Gets the overScript.
	 * @return {@link ScriptObject}
	 */
	public ScriptObject getOverScript() {
		return overScript;
	}
	/**
	 * Gets the poisonous
	 * @return {@link short}
	 */
	public short getPoisonous() {
		return poisonous;
	}
	/**
	 * Gets the poisonous_count
	 * @return {@link short}
	 */
	public short getPoisonous_count() {
		return poisonous_count;
	}
	/**
	 * Gets the pos
	 * @return {@link Vector3}
	 */
	public Vector3 getPos() {
		return pos;
	}
	public float getScale() {
		return scale;
	}

	/**
	 * Gets the script.
	 * @return {@link ScriptObject}
	 */
	public ScriptObject getScript() {
		return script;
	}
	public float getShopMultiplier() {
		return shopMultiplier;
	}
	/**
	 * Gets the show
	 * @return {@link short}
	 */
	public short getShow() {
		return show;
	}
	public int getSpells_onItem(final int index) {
		return spells_on[index];
	}

	public short getStat_count() {
		return stat_count;
	}
	public short getStat_sent() {
		return stat_sent;
	}
	/**
	 * Gets the targetinfo
	 * @return {@link long}
	 */
	public int getTargetinfo() {
		return targetinfo;
	}
	/**
	 * Determines if the {@link InteractiveObject} has a specific flag set.
	 * @param flag the flag
	 * @return true if the object has the flag set; false otherwise
	 */
	public boolean hasGameFlag(final int flag) {
		return (gameFlags & flag) == flag;
	}
	/**
	 * Determines if the {@link InteractiveObject} has a specific flag set.
	 * @param flag the flag
	 * @return true if the object has the flag set; false otherwise
	 */
	public boolean hasIoFlag(final int flag) {
		return (ioflags & flag) == flag;
	}
	public boolean hasItemData() {
		return _itemdata != null;
	}
	public boolean hasMainEvent() {
		return mainevent != null && mainevent.length() > 0;
	}
	public boolean hasNpcData() {
		return _npcdata != null;
	}
	/**
	 * Determines if the {@link InteractiveObject} has a specific flag set.
	 * @param flag the flag
	 * @return true if the object has the flag set; false otherwise
	 */
	public boolean hasTypeFlag(final int flag) {
		return (type_flags & flag) == flag;
	}
	/**
	 * Gets the flag indicating whether this object was loaded by script.
	 * @return true if the object is loaded by script; false otherwise
	 */
	public boolean isScriptload() {
		return scriptload;
	}
	public void removeGameFlags(final int flag) {
		gameFlags = gameFlags & ~flag;
	}
	public void removeIOGroup(final int index) {
		iogroups[index] = null;
		int len = iogroups.length;
		if (index < len) {
			// create temporary array
			byte[][] temp = new byte[len - 1][];
			for (int i = 0, j = 0; i < len; i++) {
				if (i == index) {
					continue;
				}
				temp[j] = new byte[iogroups[i].length];
				System.arraycopy(iogroups[i], 0, temp[j], 0, iogroups[i].length);
				j++;
			}
			iogroups = temp;
		}
		nb_iogroups--;
	}
	/**
	 * Sets the dmg_sum
	 * @param dmg_sum the dmg_sum to set
	 */
	public void setDmg_sum(float dmg_sum) {
		this.dmg_sum = dmg_sum;
	}
	public void setDurability(final float val) {
		durability = val;
	}
	void setFilename(final String val) {
		filename = val;
	}
	void setIdent(final long val) {
		ident = val;
	}
	public void setIgnit_light(long ignit_light) {
		this.ignit_light = ignit_light;
	}

	/**
	 * Sets the ignition
	 * @param ignition the ignition to set
	 */
	public void setIgnition(float ignition) {
		this.ignition = ignition;
	}
	public void setInventory(InventoryData inventory) {
		this.inventory = inventory;
	}
	public void setInvisibility(final float val) {
		invisibility = val;
	}
	/**
	 * Sets the lastanimtime
	 * @param val the lastanimtime to set
	 */
	public void setLastanimtime(final long val) {
		lastanimtime = val;
	}
	/**
	 * Sets the mainevent
	 * @param val the mainevent to set
	 */
	public void setMainevent(final String val) {
		mainevent = val;
	}
	public void setMaxDurability(float maxDurability) {
		this.maxDurability = maxDurability;
	}
	public void setNb_iogroups(short nb_iogroups) {
		this.nb_iogroups = nb_iogroups;
	}
	/**
	 * Sets the nb_lastanimvertex
	 * @param nb_lastanimvertex the nb_lastanimvertex to set
	 */
	public void setNb_lastanimvertex(long nb_lastanimvertex) {
		this.nb_lastanimvertex = nb_lastanimvertex;
	}
	/**
	 * Sets the ouch_time
	 * @param ouch_time the ouch_time to set
	 */
	public void setOuch_time(long ouch_time) {
		this.ouch_time = ouch_time;
	}
	/**
	 * Sets the overriding script
	 * @param val the overriding script to set
	 */
	public void setOverScript(final ScriptObject val) {
		overScript = val;
	}
	/**
	 * Sets the poisonous
	 * @param poisonous the poisonous to set
	 */
	public void setPoisonous(short val) {
		poisonous = val;
	}
	/**
	 * Sets the poisonous_count
	 * @param poisonous_count the poisonous_count to set
	 */
	public void setPoisonous_count(short poisonous_count) {
		this.poisonous_count = poisonous_count;
	}
	/**
	 * Sets the pos
	 * @param pos the pos to set
	 */
	public void setPos(Vector3 pos) {
		this.pos = pos;
	}
	public void setScale(float scale) {
		this.scale = scale;
	}
	/**
	 * Sets the script
	 * @param val the script to set
	 */
	public void setScript(final ScriptObject val) {
		script = val;
	}
	/**
	 * Sets the flag indicating whether this object was loaded by script.
	 * @param val the flag to set
	 */
	public void setScriptload(final boolean val) {
		scriptload = val;
	}
	/**
	 * Sets the show
	 * @param show the show to set
	 */
	public void setShow(short show) {
		this.show = show;
	}
	public void setStat_count(short stat_count) {
		this.stat_count = stat_count;
	}
	public void setStat_sent(short stat_sent) {
		this.stat_sent = stat_sent;
	}
	/**
	 * Sets the targetinfo
	 * @param targetinfo the targetinfo to set
	 */
	public void setTargetinfo(int val) {
		targetinfo = val;
	}
}
